import { request } from '@pkg/request/src';

export enum Api {
  list = '/manager/user/page',
  save = '/manager/user/add',
  edit = '/manager/user/update',
  remove = '/manager/user/remove',
  export = '/manager/user/export',
  isExistByUsername = '/manager/user/isExistByUsername',
  unLock = '/manager//user/unLock',
  organizationList = 'system/organization/list',
  importExcel = '/sys/user/importExcel',
  exportXls = '/sys/user/exportXls',
  getAuthRoleList = 'role/getAuthRoleList',
  getAuthCompanyList = 'company/getAuthCompanyList',
  setUserRole = '/manager/user/setRole',
  setCompany = '/manager/user/setCompany',
  getAuthDeptList = '/manager/user/getAuthDeptList',
  setDept = '/manager/user/setDept',
  setStatus = '/manager/user/setStatus',
  getUserInfo = '/manager/user/get',
  checkUser = '/manager/user/checkUser',
  setWaitCheck = '/manager/user/setWaitCheck',
  updatePassword = '/manager/user/update/password',
  querySetCompany = '/companyBaseUser/querySetCompany',
  setBusCompany = '/companyBaseUser/setBusCompany',
  busCompanyList = '/busCompany/list',
  getDataTagList = '/dataTag/list',
  querySetDataTag = '/userDataTag/querySetDataTag',
  setUserDataTag = '/userDataTag/setUserDataTag',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 保存用户角色
 * @param params
 * @param isUpdate
 */
export const saveOrUpdateUser = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  let handlerName = isUpdate ? '' : 'adminUserAddHandler';
  //params.handlerName = handlerName
  return request.post({ url: url, params });
};

/**
 * 加载可授权角色和已授权角色
 * @param params
 */
export const getAuthRoleList = params => {
  return request.get({ url: Api.getAuthRoleList, params });
};

/**
 * 设置用户角色
 * @param params
 */
export const setUserRole = params => {
  return request.post({ url: Api.setUserRole, params });
};

/**
 * 设置用户企业
 * @param params
 */
export const setUserCompany = params => {
  return request.post({ url: Api.setCompany, params });
};
/**
 * 加载可授权企业和已授权企业
 * @param params
 */
export const getAuthCompanyList = params => {
  return request.get({ url: Api.getAuthCompanyList, params });
};

/**
 * 设置用户部门
 * @param params
 */
export const setUserDept = params => {
  return request.post({ url: Api.setDept, params });
};
/**
 * 加载可授权部门和已授权部门
 * @param params
 */
export const getAuthDeptList = params => {
  return request.get({ url: Api.getAuthDeptList, params });
};

/**
 * 获取机构
 */
export const getOrganizationList = params =>
  request.get(
    { url: Api.organizationList, params },
    {
      errorMessageMode: 'none',
      successMessageMode: 'none',
    },
  );

/**
 * 获取某用户设置的合作企业
 */
export const querySetCompany = params =>
  request.get(
    { url: Api.querySetCompany, params },
    {
      errorMessageMode: 'none',
      successMessageMode: 'none',
    },
  );
/**
 * 获取某用户设置的合作企业
 */
export const setBusCompany = params =>
  request.post(
    { url: Api.setBusCompany, params },
    {
      errorMessageMode: 'none',
      successMessageMode: 'success',
    },
  );
/**
 * 获取合作企业
 */
export const getBusCompanyList = params =>
  request.get(
    { url: Api.busCompanyList, params },
    {
      errorMessageMode: 'none',
      successMessageMode: 'none',
    },
  );

export const setStatus = (userId: number) =>
  request.post({
    url: Api.setStatus,
    params: { userId: userId },
  });

export const getUserInfo = params =>
  request.get(
    {
      url: Api.getUserInfo,
      params: params,
    },
    {
      errorMessageMode: 'none',
      successMessageMode: 'none',
    },
  );

export const isExistByUsername = (userName: string) =>
  request.post({
    url: Api.isExistByUsername,
    params: { userName: userName },
  });

export const getDataTagList = params =>
  request.get(
    {
      url: Api.getDataTagList,
      params: params,
    },
    {
      errorMessageMode: 'none',
      successMessageMode: 'none',
    },
  );
export const querySetDataTag = params =>
  request.get(
    {
      url: Api.querySetDataTag,
      params: params,
    },
    {
      errorMessageMode: 'message',
      successMessageMode: 'success',
    },
  );

export const setUserDataTag = params =>
  request.post(
    {
      url: Api.setUserDataTag,
      params: params,
    },
    {
      errorMessageMode: 'message',
      successMessageMode: 'success',
    },
  );
